# /usr/bin/env python3.6
# -*- encoding: utf-8 -*-
"""
@File    : models.py
@Time    : 2020/2/2 0002 13:42
@Author  : zhangbing
@Email   : 18829172841@163.com
@Software: PyCharm
"""

from datetime import datetime

from App.ext import db


class BaseAnimal(db.Model):
    __abstract__ = True
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True, nullable=False)

    def save(self):
        try:
            db.session.add(self)
            db.session.commit()
            return True
        except  Exception  as  e:
            print(e)
            return False

    def delete(self):
        try:
            db.session.delete(self)
            db.session.commit()
            return True
        except  Exception  as  e:
            return False


class User(BaseAnimal):
    email = db.Column(db.String(120), unique=True, nullable=False)
    loginname = db.Column(db.String(128), unique=True)
    password = db.Column(db.String(256))
    create_date = db.Column(db.DATETIME, default=datetime.now)


class Goods(BaseAnimal):
    price = db.Column(db.String(80), nullable=False)


if __name__ == "__main__":
    pass
